/*
 * @(#)F5PoolCollector
 *
 * Copyright 2001-2005 友联创新科技
 * 
 */
package com.sinodata.bsm.cicp.collector.net.f5;

import java.util.Arrays;
import java.util.List;

import org.apache.log4j.Logger;

import com.sinodata.bsm.cicp.collector.Collector;
import com.sinodata.bsm.common.vo.ResPropertyValue;
import com.union.net.discovery.agent.ext.F5;
import com.union.net.discovery.agent.ext.F5.LtmVirtualServStatEntry;

/**
 * F5PoolCollector.java
 * <p>
 * F5 连接池指标采集
 *
 * @author 李祥军 lixj@uni-mon.com
 * @version 1.0 
 * @Date 2010-6-28
 */
public class F5VirtualServerCollector extends Collector {
    static Logger logger = Logger.getLogger(F5VirtualServerCollector.class);
    static String[] ParamMeta = { "共同体", "F5 Virtual Server 名称" };
    static String[] PropMeta = { "vsPktsIn", "vsBytesIn", "vsPktsOut", "vsBytesOut", "vsCurConns", "vsTotConns", "vsMaxConns", "vsNoNodeErrs" };

    @Override
    public List<ResPropertyValue> collect(String ip) {
        logger.warn(ip + ":" + getParamMap().get(ParamMeta[0]) + ":" + getParamMap().get(ParamMeta[1]));
        F5 f5 = F5.getF5(ip, getParamMap().get(ParamMeta[0]));
        if (f5 != null && f5.getLtmVirtualServStatTable() != null) {
            List<LtmVirtualServStatEntry> pools = f5.getLtmVirtualServStatTable();
            String poolName = getParamMap().get(ParamMeta[1]);
            for (LtmVirtualServStatEntry entry : pools) {
                String statName = entry.getLtmVirtualServStatName();
                logger.warn(statName);
                if (poolName.equals(statName)) {
                    ResPropertyValue propertyValueX = new ResPropertyValue();
                    propertyValueX.setValues(ResPropertyValue.createPropValue(entry.getLtmVirtualServStatClientPktsIn(), PropMeta[0]), ResPropertyValue.createPropValue(entry.getLtmVirtualServStatClientBytesIn(), PropMeta[1]), ResPropertyValue.createPropValue(entry.getLtmVirtualServStatClientPktsOut(), PropMeta[2]), ResPropertyValue.createPropValue(entry.getLtmVirtualServStatClientBytesOut(), PropMeta[3]), ResPropertyValue.createPropValue(entry.getLtmVirtualServStatClientCurConns(), PropMeta[4]), ResPropertyValue.createPropValue(entry.getLtmVirtualServStatClientTotConns(), PropMeta[5]), ResPropertyValue.createPropValue(entry.getLtmVirtualServStatClientMaxConns(), PropMeta[6]), ResPropertyValue.createPropValue(entry.getLtmVirtualServStatNoNodesErrors(), PropMeta[7]));
                    return Arrays.asList(propertyValueX);
                }

            }
        }
        logger.warn(ip + getParamMap().get(ParamMeta[0]) + f5.getLtmVirtualServStatTable());
        return null;
    }

    @Override
    public String[] getParamMeta() {
        return ParamMeta;
    }

    @Override
    public String[] getPropMeta() {
        return PropMeta;
    }

}
